package cn.jcet.mapreduce.kv;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @author 鲜磊
 * @Date 2020/12/7 22:36
 */
public class KVTextReduce extends Reducer<Text,IntWritable,Text,IntWritable> {

    private IntWritable v = new IntWritable();

    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
            // 计数器
        int sum = 0;

        for (IntWritable count : values) {
            sum += count.get();
        }
        v.set(sum);
        // 写出
        context.write(key,v);
    }
}
